package com.asset.dispoal.file.bank.domain.service.command;

import com.asset.dispoal.file.bank.domain.db.mapper.FileBankMapper;
import com.asset.dispoal.file.bank.dto.FileBankStatisticsRequest;
import com.asset.dispoal.file.bank.dto.FileBankStatisticsResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.springboot.protocol.Result;

@Component
public class FileBankQueryStatisticsCommand implements BaseCommand<FileBankStatisticsRequest, Result<FileBankStatisticsResponse>> {

    @Autowired
    private FileBankMapper fileBankMapper;

    public Result<FileBankStatisticsResponse> execute(FileBankStatisticsRequest statisticsRequest) {
        FileBankStatisticsResponse response = fileBankMapper.querySumStatistics(statisticsRequest);
        if (response != null) {
            response.setResponseList(fileBankMapper.querySumStatisticsDetail(statisticsRequest));
        } else {
            response = new FileBankStatisticsResponse();
        }

        return Result.ok(response);
    }
}